package br.com.caim.viewcontroller.receb;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.mail.Message;
import javax.mail.MessagingException;

import org.displaytag.decorator.TableDecorator;

public class CaixaEntradaDecorator extends TableDecorator {
	
	public String getAssunto() throws MessagingException {
		Message message = (Message) getCurrentRowObject();
		return message.getSubject();
	}
	
	public String getFrom() throws MessagingException {
		Message message = (Message) getCurrentRowObject();
		String de = message.getFrom()[0].toString();
		int index = de.indexOf("@");
		
		return de.substring(0, index);
	}
	
	public String getDataEnvio() throws MessagingException {
		Message message = (Message) getCurrentRowObject();
		String strFormatted = "";
		Date data = message.getSentDate();
		
		if(data == null) {
			strFormatted = " - ";
		} else {
			strFormatted = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(data);			
		}
		
		return strFormatted;
	}
}
